#include "wds_pickup_collection.h"




WDSPickupCollection::WDSPickupCollection(WDSPickup::PICKUP_TYPES Type )
{

}
	
WDSPickupCollection::~WDSPickupCollection()
{
	Clear();
}

void		WDSPickupCollection::Render(const math::Vec2& Offset,float Scale)
{
	for(unsigned int i = 0; i < m_Pickups.size(); i++)
	{
		WDSPickup*  pPickup = m_Pickups[i];
		pPickup->Render(Offset,Scale);
	}
}

void		WDSPickupCollection::RenderShadow(const math::Vec2& Offset,float Scale)
{
	for(unsigned int i = 0; i < m_Pickups.size(); i++)
	{
		WDSPickup*  pPickup = m_Pickups[i];
		pPickup->RenderShadow(Offset,Scale);
	}
}
	
void		WDSPickupCollection::RenderDebug(const math::Vec2& Offset,float Scale)
{
	for(unsigned int i = 0; i < m_Pickups.size(); i++)
	{
		WDSPickup*  pPickup = m_Pickups[i];
		pPickup->RenderDebug(Offset,Scale);
	}
}

void		WDSPickupCollection::Tick(float dt)
{
	for(unsigned int i = 0; i < m_Pickups.size(); i++)
	{
		WDSPickup*  pPickup = m_Pickups[i];
		pPickup->Tick(dt);
	}
}


void		WDSPickupCollection::Clear()
{
	for(unsigned int i = 0; i < m_Pickups.size(); i++)
	{
		WDSPickup*  pPickup = m_Pickups[i];
		pPickup->Clear();
		UTIL_SAFE_DELETE(pPickup);
	}
	m_Pickups.resize(0);
}

void		WDSPickupCollection::Spawn(WDSPickup::PICKUP_TYPES Type , const math::Vec2& P )
{
	
	bool	bSpawn =false;
	WDSPickup*  pObj;
	
	pObj = NULL;
	bSpawn =false;
	for( int i = 0; i < (int)m_Pickups.size(); i++)
	{
		pObj = m_Pickups[i];
		if(!pObj->IsAlive())
		{
			
			bSpawn = true;
			i = (int)m_Pickups.size();
		}
	}

	if(!bSpawn)
	{
		
		pObj = CreatePickup(Type , P);
		if(pObj)
			m_Pickups.push_back(pObj);    			
		
	}

	if(pObj)
		pObj->ReSpawn();
	
	
}



WDSPickup*		WDSPickupCollection::GetPickupByIndex(int Index)
{
	return m_Pickups[Index];
}

WDSPickup::PICKUP_TYPES			WDSPickupCollection::HitTest(const math::Vec2& P, float Radius,  float Scale)
{
	WDSPickup::PICKUP_TYPES PickupType;
	for(unsigned int i = 0; i < m_Pickups.size(); i++)
	{
		WDSPickup*  pPickup = m_Pickups[i];
		PickupType = pPickup->HitTest(P, Radius, Scale);
		if( PickupType > WDSPickup::PICKUP_TYPE_NONE)
			return PickupType;
	}
	return WDSPickup::PICKUP_TYPE_NONE;
}

WDSPickup*		WDSPickupCollection::CreatePickup(WDSPickup::PICKUP_TYPES Type, const math::Vec2& P)
{
	return new WDSPickup(Type,P);
}